#ifndef FFMPEGWINDOW_H
#define FFMPEGWINDOW_H

#include <QWidget>
#include <QTimer>
#include "deviceinformation.h"
extern "C" {
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavdevice/avdevice.h>
#include "libswscale/swscale.h"
#include "libavutil/imgutils.h"
#include <libavformat/avio.h>
#include <libavutil/file.h>
#include <SDL/SDL.h>
}
#include <QMainWindow>
#include <QFile>
namespace Ui {
class FFmpegWindow;
}

class FFmpegWindow : public QMainWindow {
    Q_OBJECT

public:

    explicit FFmpegWindow(QWidget *parent = nullptr);
    ~FFmpegWindow();
    void openffmpegcam();
    void initFFmpegWindow();
    void opencam();
    int  sfp_refresh_thread();
    void show_dshow_device();
    void testav();
    int  SDLInit();
    void addSDL();

private slots:

    void on_pushButtonShowDeviceInfo_clicked();


    void on_pushButtonOpenFFmpeg_clicked();

private:

    Ui::FFmpegWindow *ui;
    int i, ret, videoindex;
    AVCodecContext *pavCodeContext;
    AVCodec *pavCodec;
    AVFormatContext *pavFormatContext;

    AVInputFormat *pavInputFormat;
    QFile *file;
    QWidget *mainWidget;
    DeviceInformation deviceinfo;
    QTimer *qtimer;
    QTime *Time;

    int position;
    int dir;

    // sdl
    AVFrame *pFrame, *pFrameYUV;
    AVPacket *packet;
    unsigned char *out_buffer;
    int got_picture;
    int screen_w, screen_h;
    SDL_Window *screen;
    SDL_Window *sdlWindow;

    SDL_Renderer *sdlRenderer;
    SDL_Texture *sdlTexture;
    SDL_Rect sdlRect;
    SDL_Thread *video_tid;
    SDL_Event event;
};

#endif // FFMPEGWINDOW_H
